'''
Copyright 2010 Indra Bagus <indra.bagus@gmail.com> 
    
Licensed under the Apache License, Version 2.0 (the "License"); 
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

    http://www.apache.org/licenses/LICENSE-2.0 
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. 
'''



class CallUtilDictLookup:
    def __init__(self,dictionary):
        self.__call__ = self.__get_information__
        self._dictionary = dictionary
        
    def __get_information__(self,val):
        try:
            return self._dictionary[val]
        except KeyError:
            return 'Unknown'

        

class EncodingTypeDict:
    arq_feedback        = {0:'Absent'       , 1:'Present'}
    extended_type       = {0:'Not Extended' , 1:'Exteded'}
    fragment_subheader  = {0:'Absent'       , 1:'Present'}    
    packing_subheader   = {0:'Absent'       , 1:'Present'}            
    
    

class MACHeaderDict:
    header_type     = { 0:'Generic'   , 1:'Bandwidth Request' }
    encrytion_type  = { 0:'Disable'   , 1:'Enable' }
    encoding_type   = EncodingTypeDict
    ext_subheader   = {0:'Absent' , 1:'Present'}
    crc_indicator   = {0:'Not Included', 1:'Included'}
    
    GetHeaderTypeInfo   = CallUtilDictLookup(header_type)
    GetEncryptionType   = CallUtilDictLookup(encrytion_type)
    GetExtSubheaderInfo = CallUtilDictLookup(ext_subheader)
    GetCrcIndInfo       = CallUtilDictLookup(crc_indicator)


 
class MACSignallingType1:
    type    = {0:'Bandwidth Request Incremental',
               1:'Bandwidth Request Aggregate',
               2:'PHY Channel report',
               3:'Bandwidth Request with UL Tx power report',
               4:'Bandwidth Request with CIR report',
               5:'Bandwidth Request with UL sleep control',
               6:'Signal to Noise Report',
               7:'CQICH allocation request'}
    
    

class ULMAPDict:
    fdd_part_change     = {0:'Possible partition change in next frame' ,
                           1:'Minimum number of frames before next possible change'}
    
    uiuc                = {0   :'Fast-feedback channel' ,
                           1   :'Burst Profile 1' ,
                           2   :'Burst Profile 2' ,
                           3   :'Burst Profile 3' ,
                           4   :'Burst Profile 4',
                           5   :'Burst Profile 5',
                           6   :'Burst Profile 6',
                           7   :'Burst Profile 7',
                           8   :'Burst Profile 8',
                           9   :'Burst Profile 9',
                           10  :'Burst Profile 10',
                           11  :'Extended UIUC 2 IE',
                           12  :'CDMA Bandwidth Request/Ranging',
                           13  :'PAPR Reduction allocation,safety/sounding zone' ,
                           14  :'CDMA Allocation IE',
                           15  :'Extended UIUC'}
    
    ranging_method      = {0:'Initial/Handover ranging over two symbols', 
                           1:'Initial/Handover ranging over four symbols', 
                           2:'BR/Periodic ranging over two symbols', 
                           3:'BR/Periodic ranging over four symbols' }
    
    dedicated_rng_ind   = {0:'OFDMA region and ranging method for normal ranging' ,
                           1:'OFDMA region and ranging method for dedicated CDMA code'}
    
    
    permutation         = {0x00:'PUSC permutation',
                           0x01:'Optional PUSC permutation',
                           0x02:'adjacent-subcarrier permutation',
                           0x03:'reserved'}
    
    
    repetion_coding_ind = {0:'No repetition coding' ,
                           1:'Repetition coding of 2' ,
                           2:'Repetition coding of 4' ,
                           3:'Repetition coding of 6'}
    
    bw_req_mandatory = {1:'Yes',
                            0:'No'}
    
    papr_reduction_safety_zone = {0:'PAPR reduction allocation',
                                  1:'Safety zone allocation'}
    
    sounding_zone       = {0:'PAPR/safety zone',
                           1:'Sounding zone allocation'}
    
    extended_uiuc       = {0x0:'Power Control IE',
                           0x1:'Reserved',
                           0x2:'AAS UL IE',
                           0x3:'CQICH Allocation IE',
                           0x4:'UL Zone IE',
                           0x5:'UL-MAP Physical Modifier IE',
                           0x6:'Reserved',
                           0x7:'UL-MAP Fast Tracking IE',
                           0x8:'UL PUSC Burst Allocation in Other Segment IE',
                           0x9:'Fast Ranging IE',
                           0xA:'UL Allocation Start IE'}
    
    amc_type = {0x00 : '1x6',
                0x01 : '2x3',
                0x02 : '3x2',
                0x03 : 'Reserved'}
    
    use_all_subchannel_info = {0x00 : 'Do not use all subchannel',
                               0x01 : 'Use all subchannel'}
    
    pilot_pattern_idx   = {0:'Pilot Pattern A',
                           1:'Pilot Pattern B',
                           2:'Pilot Pattern C',
                           3:'Pilot PatternD'}
    pow_correction_ind = {0x00:'no change',
                          0x01:'+2 dB',
                          0x02:'-1 dB',
                          0x03:'-2 dB',
                          0x04:'-4 dB',
                          0x05:'-6 dB',
                          0x06:'+4 dB',
                          0x07:'+6 dB'}

    GetUIUCInfo                 = CallUtilDictLookup(uiuc)
    GetRangingMethodInfo        = CallUtilDictLookup(ranging_method)
    GetDedicatedRangingIndInfo  = CallUtilDictLookup(dedicated_rng_ind)
    GetRepetCodingIndInfo       = CallUtilDictLookup(repetion_coding_ind)
    GetBwReqMandatoryInfo       = CallUtilDictLookup(bw_req_mandatory)
    GetPAPRRedSafetyZoneInfo    = CallUtilDictLookup(papr_reduction_safety_zone)
    GetSoundingZoneInfo         = CallUtilDictLookup(sounding_zone)
    GetExtendedUIUC             = CallUtilDictLookup(extended_uiuc)
    GetPermutationInfo          = CallUtilDictLookup(permutation)
    GetAMCTypeInfo              = CallUtilDictLookup(amc_type)
    GetUseAllSubchIndInfo       = CallUtilDictLookup(use_all_subchannel_info)
    GetPilotPatternIdxInfo      = CallUtilDictLookup(pilot_pattern_idx)
    GetPowCorrectionIndInfo     = CallUtilDictLookup(pow_correction_ind)
    

   
class DLMAPDict:
    diuc_extended  = {  0x0:'Channel Measurement',
                        0x1:'STC Zone',
                        0x2:'AAS DL',
                        0x3:'Data Location in Another BS IE',
                        0x4:'CID Switch',
                        0x5:'Reserved',
                        0x6:'Reserved',
                        0x7:'HARQ Map Pointer',
                        0x8:'PHYMOD DL IE',
                        0x9:'Reserved',
                        0xA:'Broadcast Control Pointer',
                        0xB:'DL PUSC Burst Allocation in Other Segment',
                        0xC:'PUSC ASCA ALLOC',
                        0xD:'H-FDD Group Switch',
                        0xE:'Extended Broadcast Control Pointer',
                        0xF:'UL Interference and Noise Level'}
    
    boosting = {0:'Normal (not boosted)',
                1:'+6dB',
                2:'-6dB', 
                3:'+9dB',
                4:'+3dB',
                5:'-3dB',
                6:'-9dB',
                7:'-12dB'}

    repet_coding_ind = ULMAPDict.repetion_coding_ind
    
    permutation         = {0x00:'PUSC permutation',
                           0x01:'FUSC permutation',
                           0x02:'Optional FUSC permutation',
                           0x03:'Adjacent subcarrier permutation'}
    
    subchannel_usage    = {0:'Do not use all subchannels',
                           1:'Use all subchannels'}
    
    stc                 = {0x00:'No STC',
                           0x01:'STC using 2/3 antennas',
                           0x02:'STC using 4 antennas',
                           0x03:'FHDC using 2 antennas'}
    
    amc_type            = {0x00:'1x6',
                           0x01:'2x3',
                           0x02:'3x2',
                           0x03:'Reserved'}
    
    midamble_presence   = {0:'Not present',
                           1:'MIMO midamble present at the first symbol in STC zone'}

    midamble_boosting   = {0:'No boost',
                           1:'Boosting (3 dB)'}
    
    antennas_2_3_select = {0:'STC using 2 antennas',
                           1:'STC using 3 antennas'}

    dedicated_pilots    = {0:'Pilot symbols are broadcast',
                           1:'Pilot symbols are dedicated'}
    
    permutation_aasdl   = {0x00:'PUSC permutation',
                           0x01:'FUSC permutation',
                           0x02:'Optional FUSC permutation',
                           0x03:'AMC',
                           0x04:'TUSC1',
                           0x05:'TUSC2'}

    preamble_type_info  = {0:'Frequency shifted preamble',
                           1:'Time shifted preamble'}
    
    diversity_map_info  = {0:'Not supported in this AAS zone',
                           1:'Supported in this AAS zone'}
    
    pilot_pattern_mod   = {0:'Not Applied',
                           1:'Applied'}
    
    pilot_pattern_index = {0x00:'Pilot pattern A',
                           0x01:'Pilot pattern B',
                           0x02:'Pilot pattern C',
                           0x03:'Pilot pattern D'}
    
    
    broadcast_sys_update={0:'For MOB_NBR-ADV Update',
                          1:'For Emergency Services Message'}

    
    GetBoostingInfo         = CallUtilDictLookup(boosting)
    GetRepetCodingIndInfo   = CallUtilDictLookup(repet_coding_ind)
    GetDIUCExtInfo          = CallUtilDictLookup(diuc_extended)
    GetSubchanUsageInfo     = CallUtilDictLookup(subchannel_usage)
    GetSTCInfo              = CallUtilDictLookup(stc)
    GetAMCTypeInfo          = CallUtilDictLookup(amc_type)
    GetMidamblePresence     = CallUtilDictLookup(midamble_presence)
    GetMidambleBoosting     = CallUtilDictLookup(midamble_boosting)
    GetAntennas_2_3_Select  = CallUtilDictLookup(antennas_2_3_select)
    GetDedicatedPilots      = CallUtilDictLookup(dedicated_pilots)
    GetPermutationInfo      = CallUtilDictLookup(permutation)
    GetPermAASDLInfo        = CallUtilDictLookup(permutation_aasdl)
    GetPreambleTypeInfo     = CallUtilDictLookup(preamble_type_info)
    GetDivMAPInfo           = CallUtilDictLookup(diversity_map_info)
    GetPilotPatternModInfo  = CallUtilDictLookup(pilot_pattern_mod)
    GetPilotPatternIdxInfo  = CallUtilDictLookup(pilot_pattern_index)
    GetBroadcastSysUpdInfo  = CallUtilDictLookup(broadcast_sys_update)
                       


class UCDDict:
    tlv_type = {2  :'Contention-based reserv timeout',
                5  :'Frequency',
                7  :'HO Ranging Start',
                8  :'HO Ranging End',
                24 :'Available UL Radio Resources',
                18 :'UL AMC Allocated phy bands bitmap',
                150:'Initial Ranging Codes',
                151:'Periodic Ranging Codes',
                152:'Bandwidth Request Codes',
                153:'Periodic ranging backoff start',
                154:'Periodic ranging backoff end',
                155:'Start of ranging codes group',
                156:'Permutation base',
                157:'UL Allocated Subchannel bitmap',
                158:'Optional permutation UL Alloc subchannel bitmap',
                159:'Band AMC Allocation Threshold',
                160:'Band AMC Release',
                161:'Threshold Band AMC Alloc Timer',
                162:'Band AMC Release Timer',
                163:'Band Status Reporting MAX Period',
                164:'Band AMC Retry Timer',
                165:'Safety Channel Allocation Threshold',
                166:'Safety Channel Release Threshold',
                167:'Safety Channel Alloc Timer',
                168:'Safety Channel Rel Timer',
                169:'Bin Status Reporting MAX',
                170:'Safety Channel Retry Timer',
                171:'HARQ ACK delay for DL Burst',
                172:'CQICH Band AMC Transition Delay',
                174:'Maximum retransmission',
                175:'Normalized C/N override',
                176:'Size of CQICH_ID field',
                177:'Normalized C/N override 2',
                185:'Band AMC Entry Average CINR',
                186:'UpperBoundAAS_PREAMBLE',
                187:'LowerBoundAAS_PREAMBLE',
                188:'Allow AAS Beam Select Messages',
                189:'Use CQICH indication flag',
                190:'MS specific up power offset adjustment step',
                191:'MS specific down power offset adjustment step',
                192:'Minimum level of power offset adjustment',
                193:'Maximum level of  power offset adjustment',
                194:'Handover Ranging Codes',
                195:'Initial ranging interval',
                196:'Tx Power Report',
                197:'Normalized C/N for  Channel Sounding',
                198:'Initial ranging backoff start',
                199:'Initial ranging_backoff end',
                200:'Bandwidth_request_backoff_start',
                201:'Bandwidth_request_backoff_end',
                202:'Uplink_burst_profile for multiple FEC',
                203:'UL PUSC Subchannel Rotation',
                205:'Relative Power Offset For UL HARQ burst',
                206:'Relative Pwr Offset UL Burst Contain MAC MM',
                207:'UL initial transmit timing',
                208:'UL PHY Mode ID',
                210:'Fast Feedback Region',
                211:'HARQ Ack Region',
                212:'Ranging Region',
                213:'Sounding Region',
                214:'MS Transmit Power Limitation Level',
                215:'H-FDD Group Switch Delay',
                216:'Frame offset',
                217:'No. PC command bits',
                217:'Country Code'}

    

    class ULBurstProfileDict:
        tlv_type = {150:'FEC Code and Mod Type',
                    151:'Ranging Data Ratio',
                    152:'Group Switch Completion Time'}
   


class DCDDict:
    tlv_type = {1  :'DL Burst Profile',
                2  :'BS EIRP',
                6  :'Channel Nr',
                7  :'TTG',
                8  :'RTG',
                9  :'EIRxPIRMax',
                10 :'Channel Switch Frame Number',
                12 :'Frequency',
                13 :'BSID',
                17 :'HARQ ACK delay for UL burst',
                19 :'Perm Type Broadcast Region HARQ zone',
                20 :'Maximum retransmission',
                21 :'Default RSSI_CINR Averaging',
                22 :'DL AMC alloc phy bands bitmap',
                23 :'Available DL Radio Resources',
                24 :'FDD DL gap',
                26 :'FDD Frame Partition Change Timer',
                31 :'H_Add Threshold',
                32 :'H_Delete Threshold',
                33 :'ASR Slot Length and Switching Period', 
                34 :'DL region definition',
                35 :'Paging Group ID',
                36 :'TUSC1 permutation active subchan bitmap',
                37 :'TUSC2 permutation active subchan bitmap',
                50 :'HO type support',
                51 :'Hysteresis margin',
                52 :'Time-to-Trigger duration',
                54 :'Trigger',
                55 :'MIH Capability Support',
                56 :'NSP Change Count TLV',
                57 :'Cell Type TLV',
                61 :'MBS zone identifier list',
                62 :'DL Coordinated Zone Indication',
                63 :'Emergency Service',
                121:'Default HO RSSI and CINR averaging',
                148:'MAC version',
                153:'Downlink_burstprofile multiple FEC',
                154:'BS Restart Count',
                155:'Connection identifier descriptor',
                156:'CDD SISO/SIMO descriptor',
                157:'CDD STC descriptor'}
    
    GetTypeInfo = CallUtilDictLookup(tlv_type)
    
    